﻿
@model ScadaWeb.Model.ScadaHtmlPageModel
@{
    ViewBag.Title = "EquipmentGroups";
    Layout = "~/Views/Shared/_LayoutForm.cshtml";
}
<div class="layui-row ">
    <input type="hidden" id="pageurl"/>
    <form class="layui-form layui-form-pane ok-form">



        <div class="layui-form-item layui-bg-cyan">
            <div class="layui-input-block">
                <button class="layui-btn btn-default" lay-submit lay-filter="search">刷新</button>
                @if (ViewBag.RoleAdd)
                {
                    <button class="layui-btn  btn-success" type="button" id="add" lay-filter="add">添加新页面</button>
                }
                </div>
        </div>
    </form>
</div>
<fieldset class='layui-elem-field layui-field-title' style='margin-top: 10px;'>
    <legend><i class='layui-icon'  >&#xe67a;</i>查询列表</legend>
</fieldset>
<div class="site-demo-flow layui-bg-cyan" id="groupequipmentcontent">

</div>
<div class="layui-layer-page layui-row" id="pageer"></div>

<script>

    layui.use(["form","okLayer", "okUtils",  "util", 'layer'], function () {

        let form = layui.form;
        let okLayer = layui.okLayer;
        let okUtils = layui.okUtils;


        let $ = layui.$;

        form.on("submit(search)", function (data) {
            curr = 0;
            getDBList();
            return false;
        });

         var allowedit = @(ViewBag.RoleEdit?"true": "false");
        var allowdel = @(ViewBag.RoleAdd?"true": "false");


        function getDBList() {
            $.get("/Scada/ScadaWebPage/List",null, function (response) {
                total = response.count;

                var content = $("#groupequipmentcontent");
                content.html("");//清空原来的内容
                var html = "";
                for (var i = 0; i < response.data.length; i++) {

                    html += ("<div class='layui-col-md3 layui-collapse ' lay-accordion style='padding: 5px;' lay-filter='realcard'> <div class='layui-colla-item' >");
                    html += ("   <div class='layui-colla-title' >");
                    html += ("  <div class='layui-btn-group'  style='padding-right: 10px;' >");
                    if (allowedit==true)
                    html += ("    <button type='button' class='layui-btn layui-btn-primary  layui-btn-sm' title='编辑页面'  onclick='modeledit(\"" + response.data[i].PageTitle + "\",\"" + response.data[i].Id + "\")'><i class='layui-icon' style='color:black' >&#xe642;</i></button>");//编辑按钮

                    if (allowdel)
                    html += ("    <button type='button' class='layui-btn layui-btn-primary  layui-btn-sm' title='删除页面'   lay-filter='del' onclick='modeldel(\"" + response.data[i].PageTitle + "\",\"" + response.data[i].Id + "\")'><i class='layui-icon'  style='color:green' >&#x1006;</i></button>");//删除按钮
                    html += ("    <button type='button' class='layui-btn layui-btn-primary  layui-btn-sm' title='复制链接'   lay-filter='del' onclick='modelcopy(\"/WebTemplate/" + response.data[i].PageUid + ".htm\")'><i class='layui-icon'  style='color:blue' >&#xe621;</i></button>");//复制页面链接
                    html += ("    <button type='button' class='layui-btn layui-btn-primary  layui-btn-sm' title='预览页面'   lay-filter='del' onclick='modelbrowser(\"/WebTemplate/" + response.data[i].PageUid + ".htm\")'><i class='layui-icon'  style='color:red' >&#xe675;</i></button>");//预览页面



                    html += ("   </div></div>");
                    html += ("   <div class='layui-colla-content  layui-show layui-bg-cyan' >");
                    html += (" <div   class='layui-form-item ' >");
                    html += ("  <fieldset class='layui-elem-field layui-field-title' style='margin-top: 10px;'>");
                    html += ("  <legend><i class='layui-icon'  style='color:green' >&#xe610;</i>" + response.data[i].PageTitle +"</legend>");
                    html += ("</fieldset>");
                    html += ("</div>");


                    html += (" <div   class='layui-form-item '  style='fontsize:15;' >");//增加一个设备数量的说明
                    html += ("<div class='layui-input-inline'  ><i class='layui-icon ' style='color:red' >&#xe667;</i>&nbsp;" + response.data[i].PageTitle + "</div>");

                    html += ("</div>");

                    html += (" <div   class='layui-form-item '  style='fontsize:15;' >");//增加一个设备数量的说明
                    html += ("<div class='layui-input-inline' ><i class='layui-icon ' style='color:blue' >&#xe679;</i>&nbsp;" + response.data[i].PageUid + "</div>");
                    html += ("</div>");

                    html += (" <div   class='layui-form-item '  style='fontsize:15;' >");//增加一个设备数量的说明
                    html += ("<div class='layui-input-inline' ><i class='layui-icon ' style='color:white' >&#xe655;</i>&nbsp;" + response.data[i].Remark + "</div>");

                    html += ("</div>");

                    html += (" <div   class='layui-form-item ' >");
                    html += ("  <fieldset class='layui-elem-field layui-field-title' style='margin-top: 10px;'>");

                    html += ("</fieldset>");
                    html += ("</div>");


                    html += ("  </div>");
                    html += ("   </div>");
                    html += ("  </div>");
                    html += ("  </div>");


                }
                content.html(html);
            });
        }
        getDBList();//
        $('#add').on('click', function () {
            okLayer.open("添加新页面", "/Scada/ScadaWebPage/Add", "70%", "90%", null, null);
        });




        window.modeldel = function (title, modelid) {
            okLayer.confirm("确定要删除" + title + "页面吗？", function (index) {
                layer.close(index);
                okUtils.ajax("/Scada/ScadaWebPage/Delete", "get", { "id": modelid }, true).done(function (response) {
                    if (response.state == "success") {
                        getDBList();
                    }


                }).fail(function (error) {
                    console.log(error)
                });
            });
        }
        window.modeledit = function (title, modelid) {
            okLayer.open(title + "页面编辑", "/Scada/ScadaWebPage/add/" + modelid, "70%", "97%", null, null);

        }

        window.modelcopy = function (url) {
            $("#pageurl").val(url);
            var target = document.getElementById("pageurl");
            // 选择内容
            var save = function (e) {
                e.clipboardData.setData('text/plain', target.value);//下面会说到clipboardData对象
                e.preventDefault();//阻止默认行为
            }
            document.addEventListener('copy', save);
            document.execCommand("copy");//使文档处于可编辑状态，不然无效
            alert("复制成功 " + target.value);

        }
        window.modelbrowser = function (url) {
            window.open(url);

        }

    })
</script>

